package com.dyava.dycache;

import com.alibaba.fastjson.TypeReference;
import com.dyava.dycache.core.CacheDefined;
import com.dyava.dycache.core.CacheEngineManager;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import java.util.concurrent.CountDownLatch;

@Component
public class DyStarter implements CommandLineRunner {
    @Resource
    CacheEngineManager cacheEngineManager;

    @Override
    public void run(String... args) throws Exception {
        cacheEngineManager.getObject("test:cache2",()->"靠");
        cacheEngineManager.deleteObject("test:cache2",null);

        CountDownLatch begin = new CountDownLatch(2);
        new Thread(()->{
            begin.countDown();
            String str = cacheEngineManager.getObject("test:cache2",()->"靠1");
            System.out.println(Thread.currentThread().getName()+" "+ str);
        }).start();

        new Thread(()->{
            begin.countDown();
            String str = cacheEngineManager.getObject("test:cache2",()->"靠2");
            System.out.println(Thread.currentThread().getName()+" "+str);
        }).start();
    }
}
